<?
header("HTTP/1.1 200 OK");
$varArray = explode("/",$REQUEST_URI);
$num = sizeof($varArray); 

$REQUEST_URI = "http://www.tcntransition.org/";

function count_all($arg)
{  
 // skip if argument is empty  
 if ($arg) {  
   // not an array, return 1 (base case)  
   if(!is_array($arg))  
   return 1;  
   // else call recursively for all elements $arg  
   foreach($arg as $key => $val)  
   $count += count_all($val);  
   return $count;  
 }  
}

$num = count_all($url_array);

// Condition 1: viewCat.php with mainID or subID
// Example Format:  www.tcntransition.org/a or www.tcntransition.org/a/3
if ( (!empty($varArray[1]) || !empty($varArray[2])) && empty($varArray[3]) ) {
	$mainCat = "/".$varArray[1];
	if ($varArray[2] == "/") { $varArray[2] = null; }
	if (!empty($varArray[2])) { $subCat  = "/".$varArray[2]; }
	else { $subCat = null; }
	include("viewCat.php");
	
// Condition 2: viewCat.php with subCat
} elseif (!empty($varArray[3])) {
	$resourcePath = "/".$varArray[1]."/".$varArray[2]."/".$varArray[3];
	$mainCat = "/".$varArray[1];
	include("viewResources.php");
} else {
	// Real 404 page
	//include("tcnError.php"); 
}
if (empty($varArray[1])) {
	//include("tcnError.php"); 
}
?>